package com.zmj.sy.mom.srv.aps.utils;

import cn.hutool.core.util.IdUtil;
import org.springframework.util.StringUtils;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.Map;

public class FileStorageUtils {
    private static Map<String, String> params = new HashMap<>();

    public static final String NEST_REPORT_TYPE = "report";
    public static final String NEST_CUT_NC_TYPE = "cutP";
    public static final String PLATE_DXF_TYPE = "dxf";
    public static final String PLATE_PNG_TYPE = "plate";
    public static final String PART_PNG_TYPE = "part";
    public static final String PART_PDF_TYPE = "partPDF";

    public static final String LOG_API_TYPE = "logApi";

    public static final String NEST_HEXAGON_TYPE = "hexagon";

    static {
        params.put(PLATE_DXF_TYPE, "/home/storage/plate-dxf/%s/%s.dxf");
        params.put(NEST_REPORT_TYPE, "/home/storage/nest-report/%s/%s.pdf");
        params.put(NEST_CUT_NC_TYPE, "/home/storage/cut-program/%s/%s.gnc");
        params.put(PART_PNG_TYPE, "/home/storage/part-png/%s/%s.png");
        params.put(PART_PDF_TYPE, "/home/storage/part-pdf/%s/%s.pdf");
        params.put(PLATE_PNG_TYPE, "/home/storage/plate-png/%s/%s.png");
        params.put(LOG_API_TYPE, "/home/storage/logapi/%s/%s.log");

        params.put(NEST_HEXAGON_TYPE, "/home/storage/hexagon/push/%s/%s.txt");
    }

    public static String getFilePath(String type, String name) {

        // 类型有：套料dxf图，套料report报告，套料cutProgram切割程序，零件part图，钢板plate图

        String filePath = params.get(type);

        if (filePath == null) {
            throw SyExceptionUtils.e("未知转换类型！");
        }

        String yyyyMM = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMM"));
        String fileName = IdUtil.fastSimpleUUID();
        if(StringUtils.hasText(name)){
            fileName = name;
        }
        return  String.format(filePath, yyyyMM, fileName);
    }

    public static String getFilePath(String type) {

        return getFilePath(type, null);
    }


}
